<!--
 * @Descripttion: 宜乔木林地统计
-->
<template>
  <div
    class="arbor-wood-wrapper"
    v-loading.fullscreen.lock="fullscreenLoading"
    element-loading-background="rgba(0, 0, 0, 0.5)"
    element-loading-text="正在查询中，请耐心等待......"
  >
    <!-- 地图 -->
    <div class="page-map">
      <map-view @initMapView="initMapViewHandler"></map-view>
    </div>
    <!-- 弹框 -->
    <WoodModal
      ref="woodModal"
      :type="'7'"
      :title="'宜乔木林地统计'"
      :view="view"
      @locationHandler="locationHandler"
      downloadPdfUrl="http://222.74.215.218:53000/wuChuan/arbor/arbor.zip"
    />
  </div>
</template>
<script>
// 地图组件
import MapView from "@/components/yc/MapView";
import WoodModal from "../components/WoodModal";
import { arbor } from "@/api/eco/eco";
import GeometryUtils from "@/utils/yc/GeometryUtils.js";
import QueryUtils from "@/utils/yc/QueryUtils";
import LayerUtils from "@/utils/yc/LayerUtils";
import SymbolUtils from "@/utils/yc/SymbolUtils";
export default {
  name: "ShrubWood",
  components: {
    MapView,
    WoodModal,
  },
  data() {
    return {
      //地图对象
      view: null,
      // 加载中
      fullscreenLoading: false,
    };
  },
  methods: {
    /**
     * 初始化地图对象
     */
    initMapViewHandler(evt) {
      this.view = evt;
      this.request();
    },
    // 请求
    async request() {
      LayerUtils.clearRenderDrawLayer(this.view);
      this.fullscreenLoading = true;
      const res = await arbor({ code: "150125" });
      this.fullscreenLoading = false;
      if (res && res.features) {
        // // 1.地图渲染
        // const graphics =  GeometryUtils.setSymbolByFeatures(res.features,this.view.spatialReference);
        // LayerUtils.getRenderDrawLayer(this.view).addMany(graphics)

        // 将返回值传递给弹出层使用
        this.$refs.woodModal.update(res.features);
      }
    },
    // 定位
    async locationHandler(row) {
      LayerUtils.clearRenderDrawLayer(this.view);
      if (row && row.hasOwnProperty("xzqdm")) {
        let code = row.xzqdm;
        let feature = null;
        if (code === "150125") {
          feature = await QueryUtils.queryAreaByCode(
            "xzq",
            this.view,
            "150125"
          );
        } else {
          feature = await QueryUtils.queryAreaByCode(
            "xzqByCode",
            this.view,
            code
          );
        }
        if (feature) {
          if (code != "150125") {
            feature.symbol = SymbolUtils.HIGHLIGHT_RENDER;
            LayerUtils.getRenderDrawLayer(this.view).add(feature);
          }
          this.view.goTo(feature);
        }
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.arbor-wood-wrapper {
  position: relative;
  width: 100%;
  height: 100%;

  .page-map {
    position: relative;
    top: 0;
    left: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
  }
}
</style>